#ifndef  SHINY_FIXTURE_HPP
# define SHINY_FIXTURE_HPP

# include <Box2D/Box2D.h>
# include "../observatory.hpp"

namespace Shiny
{
  namespace Applejack
  {
    class Body;

    class Fixture
    {
    public:
      Fixture(const std::string& name, b2Fixture* fixture) : _name(name), _fixture(fixture) {}
      operator           b2Fixture*() const                        { return (_fixture);      }
      bool               operator==(const std::string& name) const { return (_name == name); }
      const std::string& GetName(void) const                       { return (_name); }

      Body&              GetBody()
      {
	return (*reinterpret_cast<Body*>((_fixture->GetBody()->GetUserData())));
      }

      static Fixture*    GetFixture(b2Fixture* fixture)
      {
        return (reinterpret_cast<Fixture*>(fixture->GetUserData()));
      }
      
      ~Fixture()
      {
	_fixture->GetBody()->DestroyFixture(_fixture);
	Destroyed.Emit(this);
      }

      Observatory::Signal<b2Contact*> ContactBegin;
      Observatory::Signal<b2Contact*> ContactEnd;
      Observatory::Signal<Fixture*>   Destroyed;

    private:
      std::string _name;
      b2Fixture*  _fixture;
    };
  }
}

#endif
